package com.flying.refdata.batchload.wind;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ImportWorker implements Runnable {
    private static Logger logger = LoggerFactory.getLogger(ImportWorker.class);
    private ExcelEquityProcessor processor;
    private Sheet sheet;
    private Row row;

    private static long count = 0;

    public ImportWorker(ExcelEquityProcessor processor, Sheet sheet, Row row) {
        this.processor = processor;
        this.sheet = sheet;
        this.row = row;
    }

    @Override
    public void run() {
        try {
            synchronized (ImportWorker.class) {
                count++;
            }
            processor.handleRow(sheet, row);
            synchronized (ImportWorker.class) {
                count--;
            }
            logger.info("Thread finished time:" + System.currentTimeMillis());
            logger.info("count:" + count);
        } catch (Throwable t) {
            logger.error("Failed to handle row. sheet name is " + sheet.getSheetName(), t);
        }
    }
}